package com.braveman.im.ui.activity;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.braveman.im.R;
import com.braveman.im.bean.FriendshipListBean;
import com.braveman.im.bean.GetMineFriendsBean;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.utils.ActivityUtils;
import com.hyphenate.easeui.domain.EaseUser;
import com.hyphenate.easeui.widget.EaseContactList;
import com.vondear.rxtools.RxBarTool;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Response;

public class InviteFriendsJoinActivity extends BaseActivity {
    private EaseContactList contactListLayout;
    private ListView listView;
    private List<EaseUser> contactList = new ArrayList<>();
    private List<GetMineFriendsBean> memberlist = new ArrayList<>();

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("邀请好友").setLeftBtnIcon(R.mipmap.back_black).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ActivityUtils.finishActivity(InviteFriendsJoinActivity.this);
            }
        });
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_invite_friends_join;
    }

    @Override
    protected void initChildView() {
    }

    @Override
    protected void initChildData() {
        ApiManager.getApi().getMineFriends().enqueue(new NetCallBack<List<GetMineFriendsBean>>() {


            @Override
            protected void onSuccess(Call<List<GetMineFriendsBean>> call, Response<List<GetMineFriendsBean>> response) {
                if (response != null) {
                    memberlist.clear();
                    memberlist = response.body();
                    contactList.clear();
                    if (memberlist != null) {
                        for (GetMineFriendsBean friendsInfo : memberlist) {
                            for (FriendshipListBean friendsList : friendsInfo.friendshipList) {
                                EaseUser easeUser = new EaseUser(friendsList.friendName);
                                easeUser.setAvatar(friendsList.friendAvatar);
                                easeUser.setInitialLetter(friendsInfo.name);
                                easeUser.memberImUsername = friendsList.friendName;
                                easeUser.headPortrait = friendsList.friendAvatar;
                                contactList.add(easeUser);
                            }

                        }
                        contactListLayout = (EaseContactList) findViewById(R.id.contact_list);
                        contactListLayout.init(contactList);
                        contactListLayout.refresh();
                        listView = contactListLayout.getListView();
                        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                                Bundle bundle = new Bundle();
//                                bundle.putString("user_id", contactList.get(i).memberImUsername);
//                                bundle.putInt("states", 3);
//                                ActivityUtils.startActivityAndFinish(mContext, ChatAllActivity.class, bundle);
                            }
                        });
                    }


                }

            }
        });
    }

    @Override
    protected void setChildViewListener() {

    }
}
